#define _CRT_SECURE_NO_WARNINGS 1

struct ListNode* removeNthFromEnd(struct ListNode* head, int n) {
    struct ListNode* slow = head;
    struct ListNode* fast = head;
    struct ListNode* sl_prev = slow;
    struct ListNode* h_pnext = head->next;

    while (n--)
    {
        fast = fast->next;
    }
    if (fast == NULL)
    {
        free(head);
        head = NULL;
        return h_pnext;
    }
    while (fast)
    {
        sl_prev = slow;
        slow = slow->next;
        fast = fast->next;
    }
    sl_prev->next = slow->next;
    free(slow);
    slow = NULL;
    return head;
}